let range = {
  from: 1,
  to: 10,
  [Symbol.iterator]() {
    console.log('什么时候调用')
    this.current = this.from;
    return this;
  },
  next() {
    if(this.current <= this.to) {
      console.log('迭代器对象访问这里', this.current)
      return {
        done: false,
        value: this.current++
      }
    } else {
      return {
        done: true
      }
    }
  }
}

// for-in
// for (const key in range) {
//   if (Object.hasOwnProperty.call(range, key)) {
//     const element = range[key];
//     console.log(key)
//   }
// }

// for-of
for (const val of range) {
  console.log(val);
}

// 字符串迭代
let str = 'test';
let iterator = str[Symbol.iterator]();
while(true) {
  let result = iterator.next();
  if(result.done) {
    break;
  }
  console.log(result.value);
}

// 类数组对象
let arrobj = {
  0: 't',
  2: 's',
  3: 't',
  length: 4
}
let like = Array.from(arrobj);
console.log(like)
console.log(like.push('o'))
console.log(like)

for (const it of like) {
  console.log(it)
}